package com.magic.babyphotos;


import java.io.File;


import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.Html;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;

public class ShareActivity extends BaseActivity
{
    private String path;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        path = getIntent().getStringExtra("result_path");
        setContentView(R.layout.share_activity);
        initUI();

    }
	 
	 public void initUI()
	 {
		 findViewById(R.id.button_done).setOnTouchListener(this);
		 findViewById(R.id.button_done).setOnClickListener(this);
		 findViewById(R.id.button_share).setOnClickListener(this);
	 }
	 
    @Override
    public boolean onTouch(View v, MotionEvent event)
    {
        switch (v.getId())
        {
            case R.id.button_done:
            {
                changeAlpha(v, event.getAction());
                break;
            }
        }

        return false;
    }
	 
	@Override
	public void onClick(View v) 
    {
        switch (v.getId())
        {
            case R.id.button_done:
            {
                this.finish();
                break;
            }
            case R.id.button_share:
            {
                Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
                shareIntent.setType("image/jpeg");
                String caption = ((EditText)findViewById(R.id.share_text)).getText().toString();

                shareIntent
                        .putExtra(
                            android.content.Intent.EXTRA_TEXT,
                            caption
                                    + "\n\n"
                                    + "Created by Babyphotos, "
                                    + Html.fromHtml("<a>"
                                            + "https://market.android.com/details?id=com.magic.babyphotos"
                                            + "</a>"));
                shareIntent.putExtra(android.content.Intent.EXTRA_TITLE, "My Baby Photo");

                Uri uri = Uri.fromFile(new File(path));

                shareIntent.putExtra(Intent.EXTRA_STREAM, uri);

                startActivity(shareIntent);
                break;
            }
        }

    }
}
